#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=3e5+5,INF=1e8;
int n,rt,A,B,tim;
vector<int>G[N];
int f[N],g[N],h[N],son[N],dfn[N],a[N],b[N],fd[N],pos[N];
inline int find(int x){
	return x==fd[x]?x:fd[x]=find(fd[x]);
}
inline void dfs1(int u,int fa){
	h[u]=1,son[u]=0;
	for(int v:G[u])if(v!=fa)
		dfs1(v,u),h[son[u]]<h[v]?son[u]=v:0;
	h[u]=h[son[u]]+1;
}
inline void dfs2(int u,int fa){
	dfn[u]=++tim;
	if(son[u])dfs2(son[u],u);
	for(int v:G[u])if(v!=fa&&v!=son[u])dfs2(v,u);
}
inline void dfs(int u,int fa,int k){
	a[u]=INF,b[u]=INF,g[u]=0;
	int s=0,mx[2]={0,0},mna[2]={INF,INF},mnb[2]={INF,INF};
	for(int v:G[u])if(v!=fa){
		dfs(v,u,k);
		a[u]=min(a[u],a[v]+1),b[u]=min(b[u],b[v]+1);
		s+=h[v]>=A?find(dfn[v]+A-1)==dfn[v]+A-1:0;
		if(h[v]>=mx[0])mx[1]=mx[0],mx[0]=h[v];
		else mx[1]=max(mx[1],h[v]);
		if(a[v]+1<=mna[0])mna[1]=mna[0],mna[0]=a[v]+1;
		else mna[1]=min(mna[1],a[v]+1);
		if(b[v]+1<=mnb[0])mnb[1]=mnb[0],mnb[0]=b[v]+1;
		else mnb[1]=min(mnb[1],b[v]+1);
	}
	if(mx[0]<A)f[u]=(u>=k&&a[u]>B);
	else f[u]=s>0;
	for(int v:G[u])if(v!=fa){
		int d=h[v]==mx[0]?mx[1]:mx[0];
		if(d<A)g[v]=u>=k&&(a[v]+1==mna[0]?mna[1]:mna[0])>B;
		else g[v]=s-(h[v]>=A?find(dfn[v]+A-1)==dfn[v]+A-1:0)>0;
	}
	if(u<k)a[u]=0;
	if(!f[u])b[u]=0;
	if(son[u])for(int t=!g[son[u]]?0:mnb[0]==b[son[u]]+1?mnb[1]:mnb[0],p=dfn[u]+1;;){
		p=find(p);
		if(p<dfn[u]+h[u]&&p<=dfn[u]+(B-t))fd[p]=p+1;
		else break;
	}
	pos[dfn[u]]=b[u]>B;
	for(int i=dfn[u]+1;i<=dfn[u]+mx[1];++i)pos[i]=find(i)==i;
	for(int v:G[u])if(v!=fa&&v!=son[u]){
		int t=!g[v]?0:mnb[0]==b[v]+1?mnb[1]:mnb[0];
		for(int i=max(0,B-t);i<h[v];++i)if(find(dfn[v]+i)==dfn[v]+i)pos[dfn[u]+i+1]=1;
	}
	for(int i=dfn[u];i<=dfn[u]+mx[1];++i)fd[i]=pos[i]?i:i+1;
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    freopen("nim.in","r",stdin);
    freopen("nim.out","w",stdout);
	cin>>n>>rt>>A>>B;
	if(A<=B)return cout<<"1\n",0;
	for(int i=1;i<n;++i){
		int u,v;cin>>u>>v;
		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}
	dfs1(rt,0),dfs2(rt,0);
	int ans=-1;
	for(int l=1,r=n;l<=r;){
		const int mid=(l+r)>>1;
		iota(fd+1,fd+n+2,1);
		dfs(rt,0,mid);
		if(f[rt])ans=mid,l=mid+1;
		else r=mid-1;
	}
	cout<<ans<<'\n';
    return 0;
}
/*
*/